'use strict';
const {
    Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
    class Order extends Model {
        /**
         * Helper method for defining associations.
         * This method is not a part of Sequelize lifecycle.
         * The `models/index` file will call this method automatically.
         */
        static associate(models) {
            models.Order.hasOne(models.OrderAddress, {as: 'address', foreignKey: 'orderId'})
            models.Order.hasMany(models.OrderProduct, {as: 'products', foreignKey: 'orderId'})
            models.Order.belongsTo(models.Express, {as: 'express', foreignKey: 'expressId'})
        }
    };
    Order.init({
        outTradeNo: DataTypes.STRING,
        userId: DataTypes.INTEGER,
        status: DataTypes.INTEGER,
        totalPrice: DataTypes.DECIMAL,
        totalNum: DataTypes.INTEGER,
        expressId: DataTypes.INTEGER,
        expressNum: DataTypes.STRING,
        paidAt: DataTypes.DATE,
        pickedAt: DataTypes.DATE,
        shippedAt: DataTypes.DATE,
        finishedAt: DataTypes.DATE
    }, {
        sequelize,
        modelName: 'Order',
    });
    return Order;
};
